home *** CD-ROM | disk | FTP | other *** search
- // FileDemo.c
- // © Copyright 1987 Consulair Corp All Rights Reserved.
- // This example shows how to read and write files using
- // standard C constructs with added Macintosh features.
- // The MacC Jr. Library allows you to fopen a file using
- // the Macintosh Standard File convention. The first 18 lines
- // of the file are then written to the output file and screen.
-
- #include <stdio.h>
-
- extern char *_SF_Name; // Name of opened file
- extern short _SF_vRefNum; // Where it opens
- main()
- {
- char c, inFileName[63];
- short invRefNum;
- int i, i1, linecount;
- FILE *file, *outfile;
- if (file = fopen(".SFin", "R"))
- {
- strcpy(inFileName, _SF_Name);
- invRefNum = _SF_vRefNum;
- if (outfile = fopen(".SFout", "W"))
- {
- printf("\rInput File: %s [vRefNum = %4X]", inFileName, invRefNum);
- printf("\rOutput File: %s [vRefNum = %4X]", _SF_Name, _SF_vRefNum);
- getchar();
- printf("\r");
- linecount = 0;
- while(!feof(file))
- {
- if ((c = fgetc(file)) == '\n')
- if (++linecount > 18) break;
- putchar(c);
- fputc(c, outfile);
- }
- fclose(outfile);
- setFileType(_SF_Name, 'TEXT');
- setFileCreator(_SF_Name, 'EDIT');
- }
- else printf("\rCould Not Open Output");
- fclose(file);
- }
- else printf("\rCould Not Open Input");
- getchar();
- }
-
-